<!--
 * @name: 
 * @Author: JiaYing
 * @LastEditors: JiaYing
 * @Date: 2022-08-21 16:59:09
 * @LastEditTime: 2022-08-21 17:10:54
 * @Description: 
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>变量提升和函数提升</title>
  </head>
  <body></body>
</html>

<script>
  fn1();
  function fn1() {
    console.log(1);
  }

  try {
    fn2();
    var fn2 = function () {};
  } catch (e) {
    // TypeError: fn2 is not a function
    console.log(e);
  }

  // 函数提升在变量提升之前
  console.log(typeof fn3); // function
  function fn3() {}
  var fn3 = 1;
  console.log(typeof fn3); // number
</script>
